函数改进参考答案
def probability_range_improved(low_range, high_range, minimum, maximum):
message = []
if isinstance(low_range, str) or isinstance(high_range, str) or isinstance(minimum, str) or isinstance(maximum, str):
print('Inputs should be numbers not strings')
return
# check that low_range is between min and max
if low_range < minimum or low_range > maximum:
message.append('Your first input needs to be between the minimum and maximum values')
# check that high_range is between min and max
if high_range < minimum or high_range > maximum:
message.append('Your second input needs to be between the minimum and maximum values')
# if no messages created, then calculate the probability
if not message:
return abs((high_range - low_range)/(maximum-minimum))
else:
for msg in message:
print(msg + '\n')
return